/**
 * Created by rouzh on 2017-8-22.
 */
$(function(){
    getdata.init();
    // myLoadUp.loadUpFnContainer();
});
var pagenow = 1;
var m_id = [];
//数据交互
var getdata = {
    init : function(){
        getdata.showMovies();
        // getdata.loadMore();
    },
    //显示所有电影接口
    showMovies : function(){
        var showMoviesUrl = 'http://60.205.208.237/onlineRetailer/movie/getratingByid.do';
        var param = {
            u_id : localStorage.getItem("uid")
        }
        publicDom.getData('post',showMoviesUrl,param,function(data){
            if(data.code == 200){
                for(var i = 0; i < data.object.length; i ++){
                    liTpl = '<li class="list">'
                        +'<div class="list_item">'
                        +'<div class="p">'
                        +'<img class="p-pic" src='+data.object[i].imgurl+'>'
                        +'</div>'
                        +'<div class="d">'
                        +'<div class="flexRow">'
                        +'<span class="movieName">'+data.object[i].m_name+'</span>'
                        +'<span class="movieIndex score">'+data.object[i].rate+'<small>分</small></span>'
                        +'</div>'
                        +'<p class="type">类型:'+data.object[i].type+'</p>'
                        +'<p class="actor">主演:'+data.object[i].actor+'</p>'
                        +'</div>'
                        +'</div>'
                        +'</li>';
                    $('#goods_container').append(liTpl);
                    m_id.push(data.object[i].m_id);
                }
                getdata.toMovieDetail();
            }else{
                layer.msg(data.message);
            }
        },function(err){
            layer.msg('未知错误!');
        })
    },
    //点击加载更多再次向后台发起请求
    // loadMore : function(){
    // 	$('.loadMore').click(function(){
    // 		pagenow = pagenow + 1;
    // 		getdata.showMovies();
    // 	})
    // }

    //跳转到电影详情页面
    toMovieDetail : function(){
        var num;
        var page = 1;
        var i;
        $('.list').click(function(){
            num = $('.list').index(this);
            console.log(num);
            console.log(m_id[num]);
            i=num;
            while(i>=10){
                page++;
                i = i-10;
            }
            console.log(page);
            window.location = "productDetail.html?"+page+"&"+m_id[num];
            page = 1;
        });
    }
}

// //下拉更新
// var myLoadUp = {
//     loadUpFnContainer:function(){
//         // dropload
//         $('.goods_wrapper').dropload({
//             scrollArea : window,
//             domDown : {
//                 domClass   : 'dropload-down',
//                 domRefresh : '<div class="dropload-refresh">↑上拉加载更多</div>',
//                 domLoad    : '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
//                 domNoData  : '<div class="dropload-noData">没有更多数据了</div>'
//             },
//             loadDownFn : function(me){
//                 // 为了测试，延迟1秒加载
//                 setTimeout(function(){
//                     pagenow = pagenow + 1;
//                     getdata.showMovies();
//                     // 每次数据加载完，必须重置
//                     me.resetload();
//                 },0);
//             }
//         });
//     }
// }




$("#infofontheads").click(function () {
    window.location="login_register.html"
    }
)
$(".set").click(function () {
        localStorage.removeItem("uid");
        localStorage.removeItem("upwd");
        window.location="myShop.html"
    }
)